package com.oocl.webmvc.controller;

import java.util.UUID;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.oocl.webmvc.factory.ServiceFactory;
import com.oocl.webmvc.pojo.Customer;
import com.oocl.webmvc.service.CustomerService;

/**
 * @description: 该controller 为单例模式，只初始化一次
 * @author  XIEMI2
 * @date Aug 7, 2017 4:22:31 PM
 * @version 1.0
 */
@Controller
public class CustomerController {

	private CustomerService customerService;
	
	public CustomerController() {  
		customerService = ServiceFactory.getCustomerService();
	}

	@RequestMapping("/addCustomer")
	public String addCustomer(Customer cust){
		cust.setId(UUID.randomUUID().toString());
		customerService.addCustomer(cust);
		return "redirect:/findAllCustomers";  
	}
	
	@RequestMapping("/findAllCustomers")
	public String findAllCustomers(Model model){
		model.addAttribute("customers", customerService.findAllCustomers());
		return "findAllCustomers";
	}
	
	@RequestMapping("/showAddCustomerPage")
	public String showAddCustomerPage(){
		return "addCustomer";
	}
}


